/*
 * @Descripttion: 
 * @version: 
 * @Author: 
 * @Date: 2022-04-24 08:59:45
 * @LastEditors: weidelong weidelong@szkingdom.com
 * @LastEditTime: 2022-05-17 11:19:38
 */
import { createStore } from 'vuex'
import createPersistedstate from 'vuex-persistedstate'

export default createStore({
    plugins: [
        createPersistedstate({
            storage: window.sessionStorage,
          key: 'saveInfo',
          paths: ['user', 'isLogin', 'chatType', 'myInfo', 'userInfo', 'userList', 'chatMessageList']
        })
      ],
  state: {
    user: {},
    isLogin: JSON.parse(sessionStorage.getItem('isLogin')) || false, //默认的登录状态,
	// 聊天记录
	andDoctorMsg: [],

  /********************************** */
    // 聊天类型
    chatType: '',
    
    // 我都信息
    myInfo: {
        img: '',
        name: ''
    },
    // 别人的信息（聊天对象）
    userInfo: {
        img: '',
        name: ''
    },
    // 用户列表
    userList: [],
    // 聊天记录
    chatMessageList: [],
  /********************************** */
  },
  mutations: {
     /********************************** */
    setUserInfo(state, data) {
      state.userInfo = data
    },
    setMyInfo(state, data) {
      state.myInfo = data
      state.isLogin = true
    },
    /*渲染用户列表 */
    socklogin(state, data) {
      state.userList = data
    },
    // 聊天记录更
    updateChatMessageList(state, data) {
        state.chatMessageList.push(data)
      },
    // 修改聊天类型
    changeChatType(state, data) {
      state.chatType = data
    },
 /********************************** */


    SET_USER_INFO(state, info){
      state.user = info
    },
	SET_DOCTOR_MSG(state, info) {
		state.andDoctorMsg = info
	}
  },
  actions: {
    saveUserInfo({ commit }, data){
      commit('SET_USER_INFO', data)
    },
	saveDoctorMsg ({ commit }, data) {
		commit('SET_DOCTOR_MSG', data)
	}
  },
  modules: {
  }
})
